package org.example.demo.service;

import java.lang.Exception;
import java.lang.String;
import java.util.Arrays;
import javax.annotation.PostConstruct;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.demo.model.bo.TeaAssetManagementCreateTeaAssetInputBO;
import org.example.demo.model.bo.TeaAssetManagementGetAssetStageInputBO;
import org.example.demo.model.bo.TeaAssetManagementGetTeaAssetDetailsInputBO;
import org.example.demo.model.bo.TeaAssetManagementMarkAsSoldInputBO;
import org.example.demo.model.bo.TeaAssetManagementStartTransportingInputBO;
import org.example.demo.model.bo.TeaAssetManagementSubmitQualityReportInputBO;
import org.example.demo.model.bo.TeaAssetManagementTeaAssetsInputBO;
import org.example.demo.model.bo.TeaAssetManagementTransferOwnershipInputBO;
import org.example.demo.model.bo.TeaAssetManagementUpdateProcessingInfoInputBO;
import org.fisco.bcos.sdk.client.Client;
import org.fisco.bcos.sdk.transaction.manager.AssembleTransactionProcessor;
import org.fisco.bcos.sdk.transaction.manager.TransactionProcessorFactory;
import org.fisco.bcos.sdk.transaction.model.dto.CallResponse;
import org.fisco.bcos.sdk.transaction.model.dto.TransactionResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@NoArgsConstructor
@Data
public class TeaAssetManagementService {
  public static final String ABI = org.example.demo.utils.IOUtil.readResourceAsString("abi/TeaAssetManagement.abi");

  public static final String BINARY = org.example.demo.utils.IOUtil.readResourceAsString("bin/ecc/TeaAssetManagement.bin");

  public static final String SM_BINARY = org.example.demo.utils.IOUtil.readResourceAsString("bin/sm/TeaAssetManagement.bin");

  @Value("${system.contract.teaAssetManagementAddress}")
  private String address;

  @Autowired
  private Client client;

  AssembleTransactionProcessor txProcessor;

  @PostConstruct
  public void init() throws Exception {
    this.txProcessor = TransactionProcessorFactory.createAssembleTransactionProcessor(this.client, this.client.getCryptoSuite().getCryptoKeyPair());
  }

  public TransactionResponse submitQualityReport(TeaAssetManagementSubmitQualityReportInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "submitQualityReport", input.toArgs());
  }

  public TransactionResponse updateProcessingInfo(TeaAssetManagementUpdateProcessingInfoInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "updateProcessingInfo", input.toArgs());
  }

  public TransactionResponse createTeaAsset(TeaAssetManagementCreateTeaAssetInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "createTeaAsset", input.toArgs());
  }

  public CallResponse teaAssets(TeaAssetManagementTeaAssetsInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "teaAssets", input.toArgs());
  }

  public CallResponse getAssetStage(TeaAssetManagementGetAssetStageInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "getAssetStage", input.toArgs());
  }

  public CallResponse getTeaAssetDetails(TeaAssetManagementGetTeaAssetDetailsInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "getTeaAssetDetails", input.toArgs());
  }

  public TransactionResponse transferOwnership(TeaAssetManagementTransferOwnershipInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "transferOwnership", input.toArgs());
  }

  public TransactionResponse markAsSold(TeaAssetManagementMarkAsSoldInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "markAsSold", input.toArgs());
  }

  public TransactionResponse startTransporting(TeaAssetManagementStartTransportingInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "startTransporting", input.toArgs());
  }

  public CallResponse deployer() throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "deployer", Arrays.asList());
  }
}
